
import matplotlib.pyplot as plt
import pandas as pd
# plt.rcParams['font.sans-serif'] = ['Times New Roman']
# plt.rcParams.update({"font.size":20})

def get_throughput_list(filename):
    df_data = pd.read_csv(filename, header = None)
    df_data.columns =['time']
 
    time_list = df_data['time'].to_list()

    noloss_time_list = []

    throughput_list = []

    for time in time_list:
        throughput = len(df_data[(df_data['time'] > time - 1000) & (df_data['time'] <= time)]) * 1500 / 1024 / 1024
        throughput_list.append(throughput)

        if time < 0:
            noloss_time_list.append(-time / 1000)
        else:
            noloss_time_list.append(time / 1000)
    return noloss_time_list, throughput_list


if __name__ == "__main__":
    time_list, throughput_list = get_throughput_list('downlink-1686214831.pps')
    plt.figure(figsize=(6, 3))
    plt.plot(time_list, throughput_list)
    plt.xlabel('Time (s)')
    plt.ylabel('Throughput (MBytes/s)')
    plt.grid()
    plt.tight_layout()
    file_name = __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.png", bbox_inches='tight')
    # plt.show()

